package com.coderfans.htmlpaser.paser;

import java.util.List;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;

/**
 * Created by ${fanchunshuai} on 2017-7-11.
 *
 * @version: V1.0
 * @Desc:  使用并发框架执行文件遍历操作
 * @Copyright (c) 2017 58到家-版权所有
 */
public class MultReadHtml {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        ForkJoinPool pool = new ForkJoinPool();
        //FolderProcessor system = new FolderProcessor("C:\\Windows","log");
        //FolderProcessor apps = new FolderProcessor("C:\\Program Files","log");
        HtmlProcessor documents = new HtmlProcessor("E:\\spiderFile\\csdn","html");
        //pool.execute(system);
        //pool.execute(apps);
        pool.execute(documents);

        do{
            //System.out.println("***********************************");
            //System.out.printf("Main: Paramllelism: %d\n",pool.getParallelism());
            //System.out.printf("Main: Active Thread: %d\n",pool.getActiveThreadCount());
            System.out.printf("Main: Task Count: %d\n",pool.getQueuedTaskCount());
            //System.out.printf("Main: Steal Count: %d\n",pool.getStealCount());
            System.out.println("***********************************");

            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }while((!documents.isDone()));
        pool.shutdown();

        List<String> results ;
        results = documents.join();
        System.out.printf("documents: %d files found.\n",results.size());
        long end = System.currentTimeMillis();
        System.out.println("end - start = "+(end - start));
        //System.out.printf("Apps: %d files found.\n",results.size());
        //System.out.printf("Documents: %d files found.\n",results.size());

    }
}
